<?php 
$defaultStronyController ='<?php
class StronyController extends Zend_Controller_Action
{
    public function init()
    {
		$this->_helper->layout->setLayoutPath(APPLICATION_PATH.\'/modules/default/layouts\');
		$bUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
		// dojo...
        Zend_Dojo::enableView( $this->view );
        Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
		$this->view->dojo()->setDjConfigOption( \'usePlainJson\', true )
      					   ->setDjConfigOption( \'parseOnLoad\', true )
      					   ->addStylesheetModule( \'dijit.themes.tundra\' )
      					   ->setLocalPath( $bUrl.\'/js/dojo/dojo/dojo.js\' )
      					   //->addLayer($bUrl.\'/js/dojo/dojo/dajana.js\')
      	    			   ;

     	$this->view->dojo()->disable();
     	
    }
    
    public function indexAction()
    {
    	
		$this->view->headTitle( \'Index\' );
		//$this->_redirect(\'Strona,Glowna,1.html\');
    }
    
    public function pokazstroneAction()
    {
    	$id = $this->_getParam( \'id\' );
    	$strStrony = new strStrony();
    	$strona = $strStrony->selectOne( $id );
    	$strona[strStrony::strona_zawartosc] = stripslashes($strona[strStrony::strona_zawartosc]);
    	$this->view->content = $strona[strStrony::strona_zawartosc];
    	$this->view->title = $strona[strStrony::strona_tytul];
    	$this->view->headTitle( $this->view->title );
    	$this->view->id = $id;
    }
}
';



$defaultLayout ='<?php echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">

<head>

	<?php
     $this->headLink()->appendStylesheet( $this->baseUrl().\'/css/style.css\' )
                 	  ->headLink(array( \'rel\' => \'shortcut icon\',
                                        \'href\' => $this->baseUrl().\'/files/img/favicon.ico\',
                 	  					\'type\' => \'image/x-icon\'),
                                        \'PREPEND\')
                 	  ;

	$this->headScript()//->appendFile( $this->baseUrl().\'/js/default/searchBoxClear.js\', $type = \'text/javascript\', $attrs = array() );
					  ;

	$this->headMeta()->appendName(\'keywords\', \'keyword1, keyword2\')
					 ->appendName(\'revisit-after\', \'7 Days\')
					 ->appendName(\'robots\', \'index, follow\')
					 ->appendName(\'rating\', \'general\')
					 ->appendName(\'copyright\', \'copy\')
					 ->appendName(\'author\', \'Information Mastery\')
					 ->appendName(\'reply-to\', \'biuro@information-mastery.pl\')
					 ->appendName(\'description\', \'opis strony\')
					 ;

	echo $this->headScript();
	echo $this->headLink();
	echo $this->headTitle();
	echo $this->headMeta();

	?>

</head>

<body>

	<?php $this->ListujStrony(); ?>

	<?php echo $this->layout()->content; ?>

</body>
</html>	
                 	  
';




$defaultHelperListujStrony = '<?php
class Zend_View_Helper_ListujStrony  extends Zend_View_Abstract
{
	protected function _run()
	{
	}
	
	public function ListujStrony( )
	{
		$strStrony= new strStrony();
		$strony = $strStrony->selectAll();
		foreach($strony as $strona)
		{
			if($strona[strStrony::strona_powiazanie] == NULL)
			{
				echo \'<a href="\'.$this->url(array($this->friendlyUrl($strona[strStrony::strona_tytul]),$strona[strStrony::strona_id]),\'defaultStronyPokazstrone\').\'">\'.$strona[strStrony::strona_tytul].\'</a><br />\';
			}
		}
	}

    public function friendlyUrl( $name )
    { 	
		return str_replace(
							array(" - "," ","-",".",",",";","ą", "ć", "ę", "ł", "ń", "ó", "ś", "ź", "ż", "Ą", "Ć", "Ę", "Ł", "Ń", "Ó", "Ś", "Ź", "Ż"),
							array("_","_","_","","","","a", "c", "e", "l", "n", "o", "s", "z", "z", "A", "C", "E", "L", "N", "O", "S", "Z", "Z"),
		 					$name
		 				  );
    }

}
';



$defaultIndex_phtml = '
index
';



$defaultPokazstrone_phtml = '
<?php
echo \'<h1>\'.$this->title.\'</h1>\'; 
echo $this->content;
?>
';



$defaultRouters = '<?php

# Strona,Glowna,1.html
$r[ \'defaultStronyPokazstrone\' ] = new Zend_Controller_Router_Route_Regex(
	\'Strona,([^-]*),([^-]*)\.html\',
    array( \'action\' => \'pokazstrone\', \'controller\' => \'strony\', \'module\' => \'default\' ),
    array( 1 => \'title\', 2 => \'id\' ),
	\'Strona,%s,%d.html\'
);

$router->addRoutes( $r );
';


$cmsStronyController ='<?php
class cms_StronyController extends Zend_Controller_Action
{
    public function init()
    {
		$this->_helper->layout->setLayoutPath(APPLICATION_PATH.\'/modules/cms/layouts\');
		$bUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
		// dojo...
        Zend_Dojo::enableView( $this->view );
        Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
		$this->view->dojo()->setDjConfigOption( \'usePlainJson\', true )
      					   ->setDjConfigOption( \'parseOnLoad\', true )
      					   ->addStylesheetModule( \'dijit.themes.tundra\' )
      					   ->setLocalPath( $bUrl.\'/js/dojo/dojo/dojo.js\' )
      					   //->addLayer($bUrl.\'/js/dojo/dojo/dajana.js\')
      	    			   ;

     	$this->view->dojo()->disable();
     	
    }

    public function indexAction()
    {
    	
		$this->view->headTitle( \'Index\' );
		$this->_redirect(\'CMS,Listuj_strony,1.html\');
    }
    
	public function listujstronyAction()
	{
		$this->view->title = \'Strony\';
    	$this->view->headTitle( $this->view->title );
    	$this->view->pid = \'strony\';
		$strony = new strStrony();
    	$rowCount = 2; 
    	$pgNum = $this->_getParam( \'page\' );
    	$result = $strony->selectAll($pgNum, $rowCount);
		$paginator = Zend_Paginator::factory( $result );
		$paginator->setCurrentPageNumber( $pgNum );
		$paginator->setItemCountPerPage( $rowCount );
		$paginator->setPageRange( 10 );
		$this->view->paginator = $paginator;
	}
  
    public function edytujstroneAction()
	{
  	   	$strony = new strStrony();
    	$strona = $strony->selectOne( $this->_getParam(\'id\') );
   		$strona[strStrony::strona_zawartosc] = stripslashes($strona[strStrony::strona_zawartosc]);
	   	$this->view->title = \'Strony - \'.$strona[ strStrony::strona_tytul ];
    	$this->view->headTitle( $this->view->title );
    	$this->view->pages = $strona;
    	$this->view->id = $strona[strStrony::strona_id];
    	$form = new StronaForm();
    	$this->view->form = $form;
        if ( $this->_request->isPost() )
    	{
    		$formData = $this->_request->getPost();
    		$strony->zUpdate( $this->_getParam(\'id\'), $formData );
    		//$form->populate( $formData );
    		$this->_redirect(\'CMS,Listuj_strony,1.html\');
    	}
    	else
    	{
    		$form->populate( $strona );
    	}
    	$this->view->pid = \'strony\';
    }  
  
	public function dodajstroneAction()
	{
        $strony = new strStrony();
    	$form = new StronaForm();
    	$this->view->form = $form;
        if ( $this->_request->isPost() )
    	{
    		$formData = $this->_request->getPost();
    		$strony->zInsert( $formData );
			$this->_redirect(\'CMS,Listuj_strony,1.html\');
    	}
    	$this->view->title = \'Strony - Dodaj stronę\';
    	$this->view->headTitle( $this->view->title );
		$this->view->pid = \'strony\';
	}
    
	public function usunstroneAction()
	{
		$strony = new strStrony();
		$strony->zDelete( $this->_getParam(\'id\') );
		$this->_redirect(\'CMS,Listuj_strony,1.html\');
	}  
}
';


$listujstrony = '
<table style="width: 500px; float: left; margin-left: 5px; margin-top: 15px; border: 1px solid #bfbfbf; text-align: center;" rules="all"; >
	<tr style="background:rgb(172,172,170);width:100%;">
		<th> Tytuł strony </th>		     
	     <th>  </th>
	</tr>
	<?php
			echo $this->partialLoop(\'_partials/strony-listing.phtml\',  $this->ListTableP(strStrony::CLASS_name,$this->paginator, $this->acl));
	?>
</table>

<div style="clear: both">
<?php echo $this->paginationControl( $this->paginator, \'Sliding\', \'p.phtml\' );?>
</div>

<?php 		
	echo $this->AclMenuOtherHelper(\'strony\',3,$this->acl);	
?>
';


$strony_listing_phtml = '
<tr style="width: 500px;" onMouseOver="this.style.background=\'#e5e5e5\'" onMouseOut="this.style.background=\'\'">
<?php 
			echo \'<td style="text-align: left; padding: 10px; width: 300px;">\'.$this->{strStrony::strona_tytul}.\'</td>\'.
			\'<td style="text-align: center;width: 150px;">\';
	    		echo $this->AclMenuOtherHelper(\'strony\',1,$this->{\'acl\'},$this->{strStrony::strona_id});
				echo $this->AclMenuOtherHelper(\'strony\',2,$this->{\'acl\'},$this->{strStrony::strona_id});
			echo \'</td>\';
?>
</tr>
';

$cmsIndex_phtml = '
CMS index
';


$CMSstronyRouters = '<?php

#CMS,Listuj_strony,1.html
$r[\'cmsStronyListujstronyAction\'] = new Zend_Controller_Router_Route_Regex(
	\'CMS,Listuj_strony,([^-]*)\.html\',
    array( \'action\' => \'listujstrony\', \'controller\' => \'strony\', \'module\' => \'cms\' ),
    array( 1 => \'page\' ),
	\'CMS,Listuj_strony,%d.html\'
);

#CMS,Edytuj_strone,1.html
$r[\'cmsStronyEdytujstroneAction\'] = new Zend_Controller_Router_Route_Regex(
	\'CMS,Edytuj_strone,([^-]*)\.html\',
    array( \'action\' => \'edytujstrone\', \'controller\' => \'strony\', \'module\' => \'cms\' ),
    array( 1 => \'id\'),
	\'CMS,Edytuj_strone,%d.html\'
);

#CMS,Usun_strone,1.html
$r[\'cmsStronyUsunstroneAction\'] = new Zend_Controller_Router_Route_Regex(
	\'CMS,Usun_strone,([^-]*)\.html\',
    array( \'action\' => \'usunstrone\', \'controller\' => \'strony\', \'module\' => \'cms\' ),
    array( 1 => \'id\'),
	\'CMS,Usun_strone,%d.html\'
);

#CMS,Dodaj_strone.html
$r[\'cmsStronyDodajstroneAction\'] = new Zend_Controller_Router_Route_Regex(
	\'CMS,Dodaj_strone.html\',
    array( \'action\' => \'dodajstrone\', \'controller\' => \'strony\', \'module\' => \'cms\' ),
    array( ),
	\'CMS,Dodaj_strone.html\'
);

$router->addRoutes( $r );
';



$StronaForm = '<?php
class StronaForm extends Zend_Form
{
	public function __construct( $options = null )
    {
        parent::__construct( $options );
        $this->setName( \'pages\' );                      
        $title = new Zend_Form_Element_Textarea(strStrony::strona_tytul);
        $title->setLabel(\'Tytuł strony: \')
  				->setAttribs(array(\'rows\' => \'1\', \'cols\' => \'80\'));
          ;
        $content = new Zend_Form_Element_FormRTE( strStrony::strona_zawartosc );
        $content->setLabel (\'Zawartość strony: \' )
        		->setAttrib(\'id\',\'strona_zawartosc\' )
        		->setAttrib(\'Height\',\'300\')
				->setAttrib(\'Width\',\'700\')
				->setAttrib(\'ToolbarSet\',\'CustomMenu\')
				;				
        $submit = new Zend_Form_Element_Submit(\'Zapisz\');
		
		$anuluj = new Zend_Form_Element_Button(\'Anuluj\');
		$anuluj->setAttrib( \'onClick\',  \'document.location = "CMS,Listuj_strony,1.html"; \' );
		
        $this->addElements(array( $title,  $content, $submit, $anuluj) );

		//--pobieranie elementów formularza
		$elementy = $this->getElements();
		
		//--Dodawanie dekoratorów do elementów formularza        
		foreach ($elementy as $variable) {
		   
		if ($variable==$submit||$variable==$reset||$variable==$anuluj)
				$variable->setDecorators(array( \'ViewHelper\', \'Description\', \'Errors\',
				array(array(\'data\'=>\'HtmlTag\'), array(\'tag\' => \'td\')) 
			));
				   
		else
				$variable->setDecorators(array( \'ViewHelper\', \'Description\', \'Errors\',
						   array(array(\'data\'=>\'HtmlTag\'), array(\'tag\' => \'td\')),
						   array(\'Label\', array(\'tag\' => \'td\')),	                   
						   array(array(\'row\'=>\'HtmlTag\'),array(\'tag\'=>\'tr\'))
				));
		}

		//--Dodawanie dekoratora dla całego formularza        
		$this->setDecorators(array(
				  \'FormElements\',
				   array(array(\'data\'=>\'HtmlTag\'),array(\'tag\'=>\'table\')),
				   \'Form\'
		));		
    }
}
';

$dirs = $dirs+array('/application/modules/default/views/scripts/strony', '/application/modules/cms/views/scripts/strony',);

$files = $files+array('/application/modules/default/controllers/StronyController.php' => $defaultStronyController);
$files = $files+array('/application/modules/default/layouts/layout.phtml' => $defaultLayout);
$files = $files+array('/application/modules/default/views/helpers/ListujStrony.php' => $defaultHelperListujStrony);
$files = $files+array('/application/modules/default/views/scripts/index/index.phtml' => $defaultIndex_phtml);
$files = $files+array('/application/modules/default/views/scripts/strony/pokazstrone.phtml' => $defaultPokazstrone_phtml);
$files = $files+array('/application/routers/defaultRouters.php' => $defaultRouters);

$files = $files+array('/application/modules/cms/controllers/StronyController.php' => $cmsStronyController);
$files = $files+array('/application/modules/cms/views/scripts/index/index.phtml' => $cmsIndex_phtml);
$files = $files+array('/application/modules/cms/views/scripts/_partials/strony-listing.phtml' => $strony_listing_phtml);
$files = $files+array('/application/routers/cmsRouters.php' => $CMSstronyRouters);
$files = $files+array('/application/forms/StronaForm.php' => $StronaForm);
$files = $files+array('/application/modules/cms/views/scripts/strony/listujstrony.phtml' => $listujstrony);
$files = $files+array('/application/modules/cms/views/scripts/strony/edytujstrone.phtml' => '<?php echo $this->form; ?>');
$files = $files+array('/application/modules/cms/views/scripts/strony/dodajstrone.phtml' => '<?php echo $this->form; ?>');
